//
//  VideoXiangqingViewController.m
//  A_HandHeldLOL
//
//  Created by Zhao YanBin on 16/1/23.
//  Copyright © 2016年 zhaoyanbin. All rights reserved.
//

#import "VideoXiangqingViewController.h"
#import "VideoXiangqingTableViewCell.h"
#import "ShiPinModel.h"
#import "AFNModel.h"
#import <UIImageView+WebCache.h>
#import "ShipindianjiViewController.h"
#import "ShipindianjidiyiViewController.h"
@interface VideoXiangqingViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *dataArr;

@property(nonatomic, retain)NSMutableArray *shipinArr;

@property(nonatomic, retain)UIView *header;

@property(nonatomic, retain)UIImageView *img;
@property(nonatomic, retain)UILabel *name;

@end

@implementation VideoXiangqingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
     [self data];
    
    [self creatableView];
    
    [self head];
   
}

-(void)creatableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height ) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerClass:[VideoXiangqingTableViewCell class] forCellReuseIdentifier:@"video"];
    [self.view addSubview:self.tableView];
    [_tableView release];
    
    
    self.header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
//    _header.backgroundColor = [UIColor blackColor];
//    [self.tableView addSubview:_header];
        _tableView.tableHeaderView = _header;
    [_header release];
    
    //开启交互
    _header.userInteractionEnabled = YES;
    
    //轻拍手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    tap.numberOfTouchesRequired = 1;
    tap.numberOfTapsRequired = 1;
    [_header addGestureRecognizer:tap];
    [tap release];
}

//轻拍手势实现
-(void)tapAction:(UITapGestureRecognizer *)tap
{
    ShipindianjidiyiViewController *diyige = [[ShipindianjidiyiViewController alloc] init];
    diyige.webwangzhi = _webwangzhi;
    [self.navigationController pushViewController:diyige animated:YES];
//    NSLog(@"qingpai: %@",tap);
}

-(void)head
{
    self.name = [[UILabel alloc] init];
    _name.frame = CGRectMake(120, 00, 150, 40);
    _name.font = [UIFont systemFontOfSize:20];
//    _name.textAlignment = NSTextAlignmentCenter;
//    _name.backgroundColor = [UIColor redColor];
    [self.header addSubview:_name];
    _name.text = _title1;
    [_name release];
    
    self.img = [[UIImageView alloc] init];
    _img.frame = CGRectMake(10, 10, 90, 80);
    _img.backgroundColor = [UIColor yellowColor];
    _img.image = [UIImage imageNamed:_tupian];
    [self.header addSubview:_img];
    [_img release];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _shipinArr.count;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    VideoXiangqingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"video" forIndexPath:indexPath];
    ShiPinModel *m = _shipinArr[indexPath.row];
    cell.neirong.text = m.desc;
    [cell.img sd_setImageWithURL:[NSURL URLWithString:m.pic_url]];
    cell.name.text = m.title;
    
    return cell;

    }

-(void)data
{
    [AFNModel GETWithURL:_wangzhi completion:^(id result) {
        NSArray *arr = result[@"data"];
        self.shipinArr = [ShiPinModel modelHanderWithArray:arr];
        
        
        
        [_tableView reloadData];
    }];

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ShipindianjiViewController *spVC = [[ShipindianjiViewController alloc] init];
    spVC.wangzhi = [_shipinArr[indexPath.item] video_url];
    [self.navigationController pushViewController:spVC animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath == 0) {
        return 100;
    }else{
        return 100;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
